package com.drinks.yiniang.adapter.user.message;

import android.content.Context;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.message.MessageJson;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.CircleImageView;
import com.hansen.library.ui.widget.image.RatioRoundImageView;

import java.util.List;

/**
 * 商品消息列表adapter
 * @author han
 * @date 2019/8/30
 */
public class GoodsMessageAdapter extends BaseQuickRCVAdapter<MessageJson.MessageList, BaseViewHolder> {

    public static final int TYPE_MSG_GOODS_LIST = 0x01;
    public static final int TYPE_MSG_COMMON_LIST = 0x02;

    private int mMsgType;

    public GoodsMessageAdapter(Context mContext, @Nullable List<MessageJson.MessageList> data) {
        super(R.layout.item_goods_message, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageJson.MessageList item) {
        if(mMsgType == TYPE_MSG_COMMON_LIST) {
            GlideUtils.loadAvatar(mContext, (CircleImageView) helper.getView(R.id.iv_goods_msg_avatar), item.getAvatar());

            helper.setText(R.id.tv_goods_msg_nickname, item.getUsername());
            helper.setText(R.id.tv_goods_msg_info, item.getBrief_content());
            helper.setText(R.id.tv_goods_msg_time, item.getLast_chat_time());
        } else {
            GlideUtils.loadAvatar(mContext, (CircleImageView) helper.getView(R.id.iv_goods_msg_avatar), item.getFrom_avatar());

            helper.setText(R.id.tv_goods_msg_nickname, item.getFrom_username());
            helper.setText(R.id.tv_goods_msg_info, item.getContent());
            helper.setText(R.id.tv_goods_msg_time, item.getCreate_time());
        }
    }

    public void setMsgType(int msgType) {
        this.mMsgType = msgType;
    }
}
